import day from 'dayjs';

function getToday() {
  return day().format('YYYY-MM-DD');
}

function getMonthEnd() {
  return day().endOf('month').format('YYYY-MM-DD');
}

function getNextMonthDate(currentDate: string, addCount: number) {
  return day(currentDate).add(addCount, 'month').format('YYYY-MM-DD');
}

function getMonthStartDay(currentDate: string) {
  const value = day(currentDate).startOf('month').day();
  return value === 0 ? 7 : value;
}

/***
 * currentDate: 当前年月日 AAAA-BB-CC
 * newDate: 新日期 DD
 * 保留当前年月，仅更改日期，最终得到的年月日为 AAAA-BB-DD
 * ***/
function setDateFrom(currentDate: string, newDate: number) {
  return day(currentDate).date(newDate).format('YYYY-MM-DD');
}

function getRandomDateInLast31Days() {
  const subCount = Math.floor(Math.random()*31)
  return day().subtract(subCount, 'days').format('YYYY-MM-DD')
}

export {getToday, getMonthEnd, getNextMonthDate, getMonthStartDay, setDateFrom, getRandomDateInLast31Days};